
  <template>
  <div class="bf-commont-template">
    <!-- <div style="padding: 0 16px ;">
          <h3>招聘需求审批</h3>
          <p>该页面代码已经自动生成，按照普通码 表增删改查 为基础生成模板</p>
          <p>生成代码对应的 vue 文件路径：D:\Zmyitem\vue-element-admin\src\beneform4j\view\hr\recruit\planaudit\index.vue</p>
          <el-alert title="注意：表格内数据为模拟数据, 如果数据格式不对，请先进行格式转换。 模拟数据文件路径：src/mock/demo.js" type="warning"> </el-alert>
        </div> -->

    <div class="clearfix bf-top-button">
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入需求名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
        </div>
        <div class="float-l padding-l">
          <el-button @click="showSearch" type="primary">高级筛选</el-button>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="margin-l margin-r">
      <el-tab-pane :label="'待审批'+ tabs.waitVett" name="waitVett">
        <bf-table :data="userData" :setting="setting" :rowAction="waitRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
      </el-tab-pane>
      <el-tab-pane :label="'已审批'+ tabs.vetted" name="vetted">
        <bf-table :data="userData" :setting="setting" :rowAction="alreadyRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
      </el-tab-pane>
    </el-tabs>
    <!--高级搜索 -->
    <bf-table-search :editForm='searchSetting' :title="'高级搜索'" ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>
    <!-- 编辑 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='detailSetting' :title="'需求详情'" ref='convertFullRosterRef' @formSubmit='convertFullRosterSubmit'></bf-table-edit>
    <!-- 审批 -->
    <bf-table-edit  :width="800" :rowNum="2" :editForm='approvalSetting' :title="'需求审批'" :submitButtons="submitButtons" ref='approvalRosterRef' :editRules="approveRules"></bf-table-edit>
    <!--详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="bfTableDetail" :title="'需求详情'" :editForm="detailSetting" :showHistory = 'true'
      :approveSetting = 'approveSetting1'></bf-table-detail>

  </div>
</template>

<script>

import { searchSetting, setting, detailSetting, approvalSetting } from './table.setting.js'
import { getRequireList, getPlanaudit, approveReqPass, approveReqNo, getRequireDetail, getRequireEndList } from './api.js'
export default {
  data() {
    return {
      searchSetting: searchSetting,
      approveSetting1: {
        procDefKey: 'recruit-req',
        businessKey: ''
      },
      searchData: '',
      userData: {
      },
      statusData: {},
      submitButtons: [
        {
          title: '通过',
          click: (form) => {
            form.action = 1
            this.approvalRosterSubmit(form)
          }
        },
        {
          title: '不通过',
          click: (form) => {
            // console.log(form)
            form.action = 0
            this.approveNoSubmit(form)
          }
        },
        {
          title: '返回',
          click: (form) => {
            this.$refs.approvalRosterRef.hiden()
          }
        }
      ],
      tabs: {
        waitVett: 0,
        vetted: 0
      },
      activeName: 'waitVett',
      waitRowAction: [
        {
          label: '查看',
          click: (item) => {
            this.approveSetting1.businessKey = item.scope.row.reqId
            this.findDetailById(item.scope.row.reqId, this.$refs.bfTableDetail.show)
          }
        },
        {
          label: '审批',
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.reqId, this.$refs.approvalRosterRef.show)
            } else {
              this.$message({
                message: '该状态不可审批',
                type: 'error'
              })
            }
          }
        }
      ],
      alreadyRowAction: [
        {
          label: '查看',
          click: (item) => {
            this.approveSetting1.businessKey = item.scope.row.reqId
            this.findDetailById(item.scope.row.reqId, this.$refs.bfTableDetail.show)
          }
        }
      ],
      setting: setting,
      detailSetting: detailSetting,
      approvalSetting: approvalSetting,
      approveRules: {
        approvalOpinion: [
          { required: true, message: '必填项', trigger: 'blur' },
          { max: 1000, message: '长度不能超过1000个字符', trigger: 'blur' }
        ]
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
    this.getTabs()
  },
  methods: {
    searchRosterSubmit(form) {
      this.searchParams.orgId = form.orgId
      this.searchParams.reqId = form.reqId
      this.searchParams.reqName = form.reqName

      this.searchList()
      this.$refs.searchRosterRef.hiden()
    },
    convertFullRosterSubmit() { },
    findDetailById(id, showCall) { // 详情
      const params = {
        reqId: id
      }
      getRequireDetail(params).then((response) => {
        showCall(response.data)
      })
    },



    approvalRosterSubmit(form) { // 审批通过
      approveReqPass(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.approvalRosterRef.hiden()
          this.searchList()
          this.getTabs();
        }
      })
    },

    approveNoSubmit(form) { // 审批不通过
      approveReqNo(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.approvalRosterRef.hiden()
          this.searchList()
          this.getTabs();
        }
      })
    },

    searchList() {
      const pageParams = this.searchParams
      if (this.activeName === 'waitVett') {
        getRequireList(pageParams).then((response) => {
          this.userData = response
        })
      } else {
        getRequireEndList(pageParams).then((response) => {
          this.userData = response
        })
      }
    },
    getTabs() {
      getPlanaudit('').then((request) => {
        this.statusData = request.data
        this.tabs.waitVett = request.data[0].count4Status1
        this.tabs.vetted = request.data[0].count4Status2
      })
    },
    editSubmit(params, formType, formList) {
      // console.log(params, formType, formList)
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSearch() {
      this.$refs.searchRosterRef.show()
    },
    showAdd() {
      this.$refs.table.showAdd()
    },
    quickSearch() {
      this.searchParams.page = 1
      this.searchParams.reqName = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.page = 1
      this.searchList()
    }
  }
}
</script>

<style scoped>

</style>
